--- 重新选择目标
--- 触发时机必须为攻击前
---@class BuffEffect62 : BaseBuffEffect
BuffEffect62 = ClientFight.CreateClass("BuffEffect62", ClientFight.BaseBuffEffect)
local t = BuffEffect62
---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = {...};
    local skill = parameters[2];
    local oldTarget = parameters[1];
    local fighter = skill.fighter;
    local skillBean = skill.skill.skillBean;
    local targetRule = buff.buffBean.f_BuffEffectValue[1];  --目标选择规则

    if (oldTarget ~= nil) then
        -- 吸引普攻子弹，忽略攻击距离
        if (skillBean.f_SkillType == 1 and skillBean.f_GeneralAttackType == 1) then
            if (FighterStateEnum.is(oldTarget, FighterStateEnum.ATTRACT_NORMAL_BULLET)) then
                return IBuffEffect.FAIL;
            end
        end
    end

    local newTarget = ClientFight.SkillClientManager.selectAttackTarget(fight, fighter, skill.skill, skillBean.f_TargetRange, skillBean.f_Target,
            targetRule, AttackUtils.getAttackRadius(fighter, skill.skill), AttackUtils.getAttackShape(fighter, skill.skill),
            fighter.position, skillBean.f_TagActivate,
            nil, false);
    if (newTarget == nil) then
        newTarget = oldTarget;
    end
    skill.target = newTarget;

    local logTarget = newTarget;
    SkillRoleMgr.savePathFile(string.format(
            "[%s][EFFECT]Fighter %s Buff%s 重新选择目标, 新目标为%s",
            fight.frame, buff.target.fighterId, buff.modelId, logTarget.fighterId
    ));
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end

t.New()